package com.itnoob.demo1;

/**
 * 折扣的访问者,继承Visitor,实现打折
 * @author zhoujun
 * @date 2025/3/26 21:08
 */
public class DiscountVisitor implements Visitor{

    /**
     * 折扣率
     */
    private double discount;

    public DiscountVisitor(double discount) {
        this.discount = discount;
    }

    @Override
    public void visit(Product product) {
        //根据商品的价格和折扣计算打折后的价格,并打印结果
        double discountedPrice =  product.getPrice() * discount;
        System.out.println("打折后的价格是=" + discountedPrice);
    }
}
